package com.koushikdutta.async.parser;

import com.koushikdutta.async.ByteBufferList;
import com.koushikdutta.async.DataEmitter;
import com.koushikdutta.async.future.Future;
import com.koushikdutta.async.future.TransformFuture;
import java.nio.charset.Charset;

public class StringParser implements AsyncParser<String> {
    public Future<String> parse(DataEmitter emitter) {
        final String charset = emitter.charset();
        return (Future) new ByteBufferListParser().parse(emitter).then(new TransformFuture<String, ByteBufferList>() {
            protected void transform(ByteBufferList result) throws Exception {
                setComplete((Object) result.readString(charset != null ? Charset.forName(charset) : null));
            }
        });
    }
}
